/*
 * Copyright (c) 2009. Silenus Consultoria, S.L.
 */
package es.silenus.detecta.model;

import java.sql.Date;

import java.util.HashSet;
import java.util.Set;


/**
 * The Class ImportedFile.
 */
public class ImportedFile implements java.io.Serializable {
	/**
	 * The id_file.
	 */
	private long id;

	/**
	 * The import_date.
	 */
	private Date importDate;

	/**
	 * The first_date.
	 */
	private Date firstDate;

	/**
	 * The lasts_date.
	 */
	private Date lastDate;

	/**
	 * The filename.
	 */
	private String filename;

	/**
	 * The total_records.
	 */
	private Integer totalRecords;

	/**
	 * The correct_records.
	 */
	private Integer correctRecords;

	/**
	 * The warned_records.
	 */
	private Integer warnedRecords;

	/**
	 * The state.
	 */
	private ImportedFileStatus status;

	/**
	 * The id_organization.
	 */
	private Organization organization;

	/**
	 * The headers.
	 */
	private Set<SurveyAnswerHeaderImported> headers;

/**
   * Constructor.
   */
	public ImportedFile() {
		importDate = new Date(System.currentTimeMillis());
		status = ImportedFileStatus.UPLOADED;
		totalRecords = 0;
		correctRecords = 0;
		warnedRecords = 0;
		firstDate = new Date(System.currentTimeMillis());
		lastDate = new Date(System.currentTimeMillis());
		headers = new HashSet<SurveyAnswerHeaderImported>();
	}

	/**
	 * Retrieves the first date.
	 *
	 * @return the first date.
	 */
	public Date getFirstDate() {
		return firstDate;
	}

	/**
	 * Sets the first date.
	 *
	 * @param firstDate the new first date
	 */
	public void setFirstDate(final Date firstDate) {
		this.firstDate = firstDate;
	}

	/**
	 * Gets the last date.
	 *
	 * @return the last date
	 */
	public Date getLastDate() {
		return lastDate;
	}

	/**
	 * Sets the last date.
	 *
	 * @param lastDate the new last date
	 */
	public void setLastDate(final Date lastDate) {
		this.lastDate = lastDate;
	}

	/**
	 * Gets the id_file.
	 *
	 * @return the id_file
	 */
	public long getId() {
		return id;
	}

	/**
	 * Sets the id.
	 *
	 * @param id the new id
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * Gets the importDate.
	 *
	 * @return the importDate
	 */
	public Date getImportDate() {
		return importDate;
	}

	/**
	 * Sets the import_date.
	 *
	 * @param importDate the new importDate
	 */
	public void setImportDate(final Date importDate) {
		this.importDate = importDate;
	}

	/**
	 * Gets the filename.
	 *
	 * @return the filename
	 */
	public String getFilename() {
		return filename;
	}

	/**
	 * Sets the filename.
	 *
	 * @param filename the new filename
	 */
	public void setFilename(final String filename) {
		this.filename = filename;
	}

	/**
	 * Gets the state.
	 *
	 * @return the state
	 */
	public ImportedFileStatus getStatus() {
		return status;
	}

	/**
	 * Sets the state.
	 *
	 * @param status the new state
	 */
	public void setStatus(final ImportedFileStatus status) {
		this.status = status;
	}

	/**
	 * Gets the total records.
	 *
	 * @return the total records
	 */
	public Integer getTotalRecords() {
		return totalRecords;
	}

	/**
	 * Sets the total records.
	 *
	 * @param totalRecords the total records
	 */
	public void setTotalRecords(final Integer totalRecords) {
		this.totalRecords = totalRecords;
	}

	/**
	 * Gets the correct_records.
	 *
	 * @return the correct_records
	 */
	public Integer getCorrectRecords() {
		return correctRecords;
	}

	/**
	 * Sets the correct records.
	 *
	 * @param correctRecords the correct records.
	 */
	public void setCorrectRecords(final Integer correctRecords) {
		this.correctRecords = correctRecords;
	}

	/**
	 * Gets the warned records.
	 *
	 * @return the warned records.
	 */
	public Integer getWarnedRecords() {
		return warnedRecords;
	}

	/**
	 * Sets the warned records.
	 *
	 * @param warnedRecords the warned records.
	 */
	public void setWarnedRecords(final Integer warnedRecords) {
		this.warnedRecords = warnedRecords;
	}

	/**
	 * Gets the id_organization.
	 *
	 * @return the id_organization
	 */
	public Organization getOrganization() {
		return organization;
	}

	/**
	 * Sets the id_organization.
	 *
	 * @param organization the new id_organization
	 */
	public void setOrganization(Organization organization) {
		this.organization = organization;
	}

	/**
	 * Retrieves the headers.
	 *
	 * @return the headers.
	 */
	public Set<SurveyAnswerHeaderImported> getHeaders() {
		return headers;
	}

	/**
	 * Set the headers.
	 *
	 * @param headers the headers.
	 */
	public void setHeaders(final Set<SurveyAnswerHeaderImported> headers) {
		this.headers = headers;
	}

	/**
	 * Add a survey answer header.
	 *
	 * @param header a survey answer header.
	 */
	public void add(final SurveyAnswerHeaderImported header) {
		header.setImportedFile(this);
		getHeaders().add(header);
	}

	/**
	 * Remove a survey answer header.
	 *
	 * @param header a survey answer header.
	 */
	public void remove(final SurveyAnswerHeaderImported header) {
		header.setImportedFile(null);
		getHeaders().remove(header);
	}

	/**
	 * Checks if objects are equal.
	 *
	 * @param o other object.
	 *
	 * @return true if equal, false otherwise.
	 */
	@Override
	public boolean equals(Object o) {
		if(this == o) {
			return true;
		}

		if(!(o instanceof ImportedFile)) {
			return false;
		}

		ImportedFile that = (ImportedFile)o;

		if(getId() != that.getId()) {
			return false;
		}

		return true;
	}

	/**
	 * Calculates the hash of this instance.
	 *
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		return (int)getId();
	}
}
